package ihm.dialog.windows;

import ihm.dialog.windows.ConnectionDialogWindow.ButtonExitListener;
import ihm.dialog.windows.ConnectionDialogWindow.ButtonSendListener;
import ihm.overlays.MainOverlay;

import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ExpandBar;
import org.eclipse.swt.widgets.ExpandItem;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import tools.Test;


public class EditAlbumDialogWindow extends Composite {

private ExpandItem networkToolsExpandItem;
private ExpandItem workflowExpandItem;
private ExpandItem quickSearchExpandItem;
private Composite workflowComposite;
private Composite searchComposite;
private ExpandBar expandBar;
private Text text;
private Composite networkToolsComposite;
private Image oldImage;
private Color tanColor;
private Shell shell;
private Button buttonSend, buttonExit;
/**
* Create the composite
* @param parent
* @param style
*/
public EditAlbumDialogWindow(Composite parent, int style) {
super(parent, style);
setLayout(new FillLayout());
createControl(this);
}

protected void createControl(Composite parent)
{
expandBar = new ExpandBar (parent, SWT.NONE);
//tanColor = new Color(parent.getDisplay(), 207, 196, 177);
expandBar.setBackground(tanColor);
Image image = Display.getDefault().getSystemImage(SWT.ICON_INFORMATION);

// First item
searchComposite = new Composite (expandBar, SWT.NONE);
GridLayout layout = new GridLayout ();
layout.numColumns = 2;
layout.marginLeft = layout.marginTop = layout.marginRight =
layout.marginBottom = 10;
layout.verticalSpacing = 10;
searchComposite.setLayout(layout);

text = new Text(searchComposite, SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
quickSearchExpandItem = new ExpandItem (expandBar, SWT.NONE, 0);
quickSearchExpandItem.setExpanded(true);
quickSearchExpandItem.setText("Titre Album");

quickSearchExpandItem.setHeight(searchComposite.computeSize(SWT.DEFAULT,
SWT.DEFAULT).y);
quickSearchExpandItem.setControl(searchComposite);

//Second item
networkToolsComposite = new Composite (expandBar, SWT.NONE);
layout = new GridLayout (6, false);
layout.marginLeft = layout.marginTop = layout.marginRight =
layout.marginBottom = 10;
layout.verticalSpacing = 10;
networkToolsComposite.setLayout(layout);

class ConnectedFriendsOverlay  implements MainOverlay {

	private Composite composite;

	private ConnectedFriendsOverlay()
	{
	}

	public ConnectedFriendsOverlay( Composite shell )
	{
		composite = new Composite( shell, SWT.BORDER );
		composite.setLayout( new GridLayout( 1, true ) );
	}

	public void update()
	{
		Link link;
		StyledText text = new StyledText( composite, SWT.NONE );
		text.setText( "Amis connect�s" );
		StyleRange style1 = new StyleRange();
		style1.start = 0;
		style1.length = 14;
		style1.fontStyle = SWT.BOLD;
		text.setStyleRange(style1);
		text.setEditable( false );

		new Label( composite, SWT.SEPARATOR | SWT.HORIZONTAL );
		for( int i = 0; i < Test.getInstance().connectedFriends.size(); i++ )
		{
			link = new Link( composite, SWT.NONE );
			link.setText( Test.getInstance().connectedFriends.get( i ) );
			/*link.addListener( SWT.Selection,
					new Listener()
			{
				public void handleEvent( Event event ) {
					System.out.println( "Selection : " + event.text );
				}
			});*/
		}
	}

}

networkToolsExpandItem = new ExpandItem (expandBar, SWT.NONE, 1);
networkToolsExpandItem.setExpanded(true);
networkToolsExpandItem.setText("Droits Amis");

networkToolsExpandItem.setHeight(networkToolsComposite.computeSize(SWT.DEFAULT,SWT.DEFAULT).y);
networkToolsExpandItem.setControl(networkToolsComposite);

// Third item
workflowComposite = new Composite (expandBar, SWT.NONE);
layout = new GridLayout (6, false);
layout.marginLeft = layout.marginTop = layout.marginRight =
layout.marginBottom = 10;
layout.verticalSpacing = 10;
workflowComposite.setLayout(layout);

Label label = new Label (workflowComposite, SWT.CHECK);
final Label importDevicesLabel = new Label (workflowComposite, SWT.CHECK);
importDevicesLabel.setText("Droit par Default");

Button button = new Button(workflowComposite, SWT.CHECK);
button.setText("Voir");

button = new Button(workflowComposite, SWT.CHECK);
button.setText("Voire Commentaire");

button = new Button(workflowComposite, SWT.CHECK);
button.setText("Commenter");

button = new Button(workflowComposite, SWT.CHECK);
button.setText("Noter");

Label label1 = new Label (workflowComposite, SWT.CHECK);
final Label importDevicesLabel1 = new Label (workflowComposite, SWT.CHECK);
importDevicesLabel1.setText("Droit Amis");

button = new Button(workflowComposite, SWT.CHECK);
button.setText("Voir");

button = new Button(workflowComposite, SWT.CHECK);
button.setText("Voire Commentaire");

button = new Button(workflowComposite, SWT.CHECK);
button.setText("Commenter");

button = new Button(workflowComposite, SWT.CHECK);
button.setText("Noter");

Label label2 = new Label (workflowComposite, SWT.CHECK);
final Label importDevicesLabel2 = new Label (workflowComposite, SWT.CHECK);
importDevicesLabel2.setText("Droit Groupe");

button = new Button(workflowComposite, SWT.CHECK);
button.setText("Voir");

button = new Button(workflowComposite, SWT.CHECK);
button.setText("Voire Commentaire");

button = new Button(workflowComposite, SWT.CHECK);
button.setText("Commenter");

button = new Button(workflowComposite, SWT.CHECK);
button.setText("Noter");

button = new Button(workflowComposite, SWT.PUSH);
button.setText("Enregistrer");
//buttonSend.addSelectionListener( new ButtonSendListener() );

button = new Button(workflowComposite, SWT.PUSH);
button.setText("Annuler");
//buttonExit.addSelectionListener( new ButtonExitListener() );

workflowExpandItem = new ExpandItem (expandBar, SWT.NONE, 1);
workflowExpandItem.setExpanded(true);
workflowExpandItem.setText("Ajouter des Droits");

workflowExpandItem.setHeight(workflowComposite.computeSize(SWT.DEFAULT,
SWT.DEFAULT).y);
workflowExpandItem.setControl(workflowComposite);}

@Override
public void dispose() {
super.dispose();
if(oldImage != null)
{
oldImage.dispose();
}
if(tanColor != null)
{
tanColor.dispose();
}
}

@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}

public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display, SWT.CLOSE);
shell.setText("Editer Album");
shell.setLayout(new FillLayout());
shell.setSize(600, 500);
EditAlbumDialogWindow composite = new EditAlbumDialogWindow(shell, SWT.FILL);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
class ButtonSendListener implements SelectionListener {
	public void widgetSelected( SelectionEvent event ) {
		CreateProfileDialogWindow.run();
		// TODO
	}

	public void widgetDefaultSelected( SelectionEvent event ) {
		CreateProfileDialogWindow.run();
		// TODO
	}
}
class ButtonExitListener implements SelectionListener {
	public void widgetSelected( SelectionEvent event ) {
		shell.close();
	}

	public void widgetDefaultSelected( SelectionEvent event ) {
		shell.close();
	}
}

}